package com.example.easybuy.service.impl;

import com.example.easybuy.entity.User;
import com.example.easybuy.mappers.UserMapper;
import com.example.easybuy.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findUser(String loginName) {
        return userMapper.findUser(loginName);
    }


    @Override
    public boolean register(Map<String, Object> map) {
        return userMapper.register(map) > 0;
    }

    @Override
    public boolean updateUser(Map<String, Object> map) {
        return userMapper.updateUser(map) > 0;
    }

    @Override
    public boolean delUser(int id) {
        return userMapper.delUser(id) > 0;
    }

    @Override
    public PageInfo<User> userByPage(Map<String, Object> map) {
        map.put("orderBy", "id desc");
        PageHelper.startPage(map);
        List<User> list = userMapper.userByPage(map);
        return new PageInfo<>(list);
    }
}